package cn.itcast.usermanage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.itcast.usermanage.bean.EasyUIPage;
import cn.itcast.usermanage.mapper.NewUserMapper;
import cn.itcast.usermanage.pojo.User;
import cn.itcast.usermanage.service.UserService;

import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class UserServiceImpl implements UserService{

//	@Autowired
//	private UserMapper userMapper;
	
	@Autowired
	private NewUserMapper newUserMapper;
	
	@Override
	public EasyUIPage queryAllUser(Integer pageNum, Integer pageSize) {


		PageHelper.startPage(pageNum, pageSize);
		List<User> users = newUserMapper.select(null);
		
		PageInfo<User> pageInfo = new PageInfo<User>(users);
		
		EasyUIPage easyUIPage = new EasyUIPage();
		//easyUIPage.setRows(users);
		easyUIPage.setRows(pageInfo.getList());
		easyUIPage.setTotal(pageInfo.getTotal());
		return easyUIPage;
	}

	@Override
	public Integer addUser(User user) {
		return this.newUserMapper.insertSelective(user);
	}

	@Override
	public Integer deleteUserByIds(List<Object>  ids) {
		Example e = new Example(User.class);
		e.createCriteria().andIn("id", ids);
		return this.newUserMapper.deleteByExample(e);
	}

}
